package com.robusta.app.auth.model;

import com.robusta.app.matchers.CompositeMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

import java.util.Date;

public class UserSessionModelMatcher extends CompositeMatcher<UserSessionModel> {
    private UserSessionModelMatcher() {}

    public static UserSessionModelMatcher isAUserSessionModel() {
        return new UserSessionModelMatcher();
    }

    public UserSessionModelMatcher withId(final Matcher<Long> idMatcher) {
        add(new TypeSafeMatcher<UserSessionModel>() {
            @Override
            public boolean matchesSafely(UserSessionModel userSessionModel) {
                return idMatcher.matches(userSessionModel.getId());
            }

            @Override
            public void describeTo(Description description) {
                description.appendText("with id = ");
                idMatcher.describeTo(description);
            }
        }); return this;
    }

    public UserSessionModelMatcher withAuthToken(final Matcher<String> authTokenMatcher) {
        add(new TypeSafeMatcher<UserSessionModel>() {
            @Override
            public boolean matchesSafely(UserSessionModel userSessionModel) {
                return authTokenMatcher.matches(userSessionModel.getToken());
            }

            @Override
            public void describeTo(Description description) {
                description.appendText("with authentication token = ");
                authTokenMatcher.describeTo(description);
            }
        }); return this;
    }

    public UserSessionModelMatcher withValidity(final Matcher<Date> validityMatcher) {
        add(new TypeSafeMatcher<UserSessionModel>() {
            @Override
            public boolean matchesSafely(UserSessionModel userSessionModel) {
                return validityMatcher.matches(userSessionModel.getValidity());
            }

            @Override
            public void describeTo(Description description) {
                description.appendText("with validity = ");
                validityMatcher.describeTo(description);
            }
        }); return this;
    }
}
